<template>
  <div class="hello">
    <el-dialog title="添加小区标签" :visible.sync="dialogAdd.show">
      <el-form :model="tag" ref="formAdd" label-width="100px" :rules="formRules">
        <el-form-item label="类型" prop="type">
          <el-input v-model="tag.type"></el-input>
        </el-form-item>
        <el-form-item label="内容" prop="info">
          <el-input v-model="tag.info"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAdd.show = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormAdd('formAdd')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import communityTagApi from '@/api/community/communityTag'

export default {
  name: 'addCommunityTag',
  props: {
    dialogAdd: Object
  },
  data () {
    return {
      tag: {// 要添加小区标签对象
        id: '', // 小区标签编号
        type: '', // 小区标签类型
        info: ''
      },
      formRules: {// 提交表单规则
        type: [{required: true, message: '类型不能为空', trigger: 'blur'}],
        info: [{required: true, message: '内容不能为空', trigger: 'blur'}]
      }
    }
  },
  methods: {
    /**
     * @description 小区标签添加
     * @param formAdd
     */
    dialogFormAdd (formAdd) {
      this.$refs[formAdd].validate((valid) => {
        if (valid) {
          communityTagApi.addCommunityTag(this.tag).then(res => {
            this.$message({
              type: 'success',
              message: '添加标签成功'
            })
            this.dialogAdd.show = false
            this.$emit('update')
          }
          )
          this.$refs[formAdd].resetFields()
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
